"""
演示视频输出
"""
import os
import cv2


# 路径全局变量
INPUT_VIDEO = 'E:/a'  # 输入视频流
OUTPUT_VIDEO = 'E:/'   # 输出视频流


if __name__ == '__main__':

    file_list = os.listdir(INPUT_VIDEO)  # 获取视频列表
    frame_list = []
    out = cv2.VideoWriter(os.path.join(OUTPUT_VIDEO + 'test.mp4'), cv2.VideoWriter_fourcc(*'XVID'), 30.0, (960, 640), True)   # 输出演示视频
    for file in range(len(file_list)):
        video_path = os.path.join(INPUT_VIDEO, str(file_list[file]))
        video_capture = cv2.VideoCapture(video_path)
        while True:
            ret, frame = video_capture.read()
            # 判断视频流中的帧是否存在
            if frame is None:
                break
            frame_list.append(frame)
            cv2.imshow('show_img', frame)
            if cv2.waitKey(1) & 0xff == ord('n'):
                continue
    for i in range(len(frame_list)):
        out.write(frame_list[i])    # 写入视频流
    cv2.destroyAllWindows()
